package com.wxit.algorithm.tree;


import java.util.LinkedList;
import java.util.Queue;

/**
 * 层序遍历
 */
public class LeetCode104_3 {

    public int maxDepth(TreeNode root) {
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        int deep = 0;
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                TreeNode poll = queue.poll();
                if (poll.left != null) {
                    queue.offer(poll.left);
                }
                if (poll.right != null) {
                    queue.offer(poll.right);
                }
            }
            deep++;
        }
        return deep;
    }
}
